Skip to content

✨ feat(launchd): resident HTTP service lifecycle (PR2 — launchd) - #15

Merged
SWSAmor merged 2 commits into
mainfrom
feat/launchd-lifecycle
Jul 24, 2026
Merged

SWSAmor merged 2 commits into
mainfrom
feat/launchd-lifecycle

Conversation

@SWSAmor

@SWSAmor SWSAmor commented Jul 24, 2026

Copy link
Copy Markdown
Owner

PR2 — launchd lifecycle

Supersedes #14 (auto-closed when #13's branch was deleted on merge). Now targets main directly (PR1 is merged). Adds only the 2 launchd-lifecycle commits (a3ef868, 04ecaec) on top of main.

Makes the single shared HTTP instance an always-resident, launchd-managed macOS service, and lets an idle resident stay lightweight.

1. Lazy/idle downstream pool (✨ feat(core))

Gated by CODE_EXECUTOR_POOL_IDLE_MS (0 = disabled = eager, the default; stdio behavior byte-for-byte unchanged). Lazy build on the first tool call (SharedCore.ensurePoolReady, idempotent); idle teardown after the last HTTP session closes (deferred while an exec is in flight; cancelled on reconnect/shutdown). Session accounting wired from the Streamable HTTP transport. SharedCore gains optional ctor injection for tests.

2. Resident launchd service + service CLI (✨ feat(service))

LaunchdService renders a resident-daemon plist (RunAtLoad+KeepAlive, ProgramArguments=[binary], env = http role/port/token/MCP_CONFIG_PATH/ALLOW_NESTED), managed via modern launchctl verbs. Plist 0600 (embeds token), XML-escaped, label charset-validated; runner + platform injectable. ensureHttpToken persists a 256-bit token 0600. code-executor-mcp service install|uninstall|status|restart CLI.

Verification

typecheck clean; 30 new unit tests; binary integration 7/7; full suite sandbox-off = no new regressions (only the known filesystem.test.ts); live resident smoke (install → launchd loads → /health 200 → uninstall clean).

🤖 Generated with Claude Code

SWSAmor and others added 2 commits July 24, 2026 16:33
The single resident HTTP instance can now stay lightweight when idle.
Gated by CODE_EXECUTOR_POOL_IDLE_MS (0 = disabled = eager, the default and
the unchanged stdio behavior):

- Lazy build: the downstream MCP pool is initialized on the FIRST tool call
  (SharedCore.ensurePoolReady, idempotent for concurrent callers) instead of
  eagerly at startup.
- Idle teardown: when the last HTTP session closes, an idle timer tears the
  pool down (MCPClientPool.disconnect) after the configured window, reclaiming
  the ~15 downstream children; the next tool call rebuilds it. Teardown is
  deferred while an execution is in flight and cancelled on reconnect or full
  shutdown.
- Session accounting is driven from the Streamable HTTP transport
  (onSessionOpen/onSessionClose), gated once per session on the sessions map.

SharedCore gains optional constructor injection (pool + connection pool) for
testability; production call sites are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the macOS launchd lifecycle for the single shared HTTP instance so it can
run as an always-resident, managed service (a host cannot spawn an HTTP MCP
server the way a stdio host does, so the server must already be running).

- LaunchdService: renders a resident-daemon plist (RunAtLoad + KeepAlive,
  ProgramArguments=[binary], EnvironmentVariables carrying the http role, port,
  bearer token, MCP_CONFIG_PATH and CODE_EXECUTOR_ALLOW_NESTED) and manages it
  via modern launchctl verbs (bootstrap/bootout/kickstart/print). Distinct from
  the StartCalendarInterval sync scheduler. Plist written 0600 (it embeds the
  token); all interpolated values XML-escaped; label charset-validated so it
  cannot traverse out of ~/Library/LaunchAgents; launchctl runner + platform
  injectable for tests.
- ensureHttpToken: read-or-generate a 256-bit bearer token persisted 0600 at
  ~/.code-executor/http-token (idempotent).
- `code-executor-mcp service install|uninstall|status|restart` CLI (argv-
  dispatched like setup/sync-wrappers), with --port/--config/--binary/--no-auth
  and a connection hint for wiring a host.

Verified live: install → launchd loads it → GET /health 200 → uninstall
removes it cleanly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@SWSAmor
SWSAmor merged commit 0bd4b09 into main Jul 24, 2026
1 of 3 checks passed
@SWSAmor
SWSAmor deleted the feat/launchd-lifecycle branch July 24, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant